//
//  ConnectorView.m
//  CocoaSynth
//
//  Created by Thomas Dupont on 19/02/10.
//  Copyright 2010 Apple Inc. All rights reserved.
//

#import "ConnectorView.h"


@implementation ConnectorView

@synthesize point1;
@synthesize point2;

- (id)initWithFrame:(NSRect)frameRect
{
	if (self = [super initWithFrame:frameRect]) {
		point1 = NSMakePoint(0, 0);
		point2 = NSMakePoint(0, 0);
	}
	return self;
}

- (void)drawRect:(NSRect)dirtyRect
{
	int distance = MAX(point1.x, point2.x) - MIN(point1.x, point2.x);
	
	NSPoint nearPoint1;
	nearPoint1.x = point1.x;
	nearPoint1.y = point1.y - 30 - distance/5;
	
	NSPoint nearPoint2;
	nearPoint2.x = point2.x;
	nearPoint2.y = point2.y - 30 - distance/5;
	
	[[NSColor blackColor] set];
	
	NSBezierPath* path = [NSBezierPath bezierPath];
	
	[path setLineWidth:10];
	[path setLineCapStyle:NSRoundLineCapStyle];
	[path setLineJoinStyle:NSRoundLineCapStyle];
	
	[path moveToPoint:point1];
	
	[path curveToPoint:point2 controlPoint1:nearPoint1 controlPoint2:nearPoint2];
	[path curveToPoint:point1 controlPoint1:nearPoint2 controlPoint2:nearPoint1];
	
	[path closePath];
	
	[path stroke];
}

@end
